package com.blame.alibaba.controller;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.messages.UserMessage;
import org.springframework.ai.chat.model.ChatResponse;
import org.springframework.ai.chat.prompt.Prompt;
import org.springframework.ai.content.Media;
import org.springframework.util.MimeTypeUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.net.URI;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 何彦声
 * Date: 2025-08-28
 * Time:
 */

@RestController
@RequestMapping("/multi")
public class ImageController {

    private final ChatClient chatClient;

    public ImageController(ChatClient chatClient) {
        this.chatClient = chatClient;
    }

    @GetMapping("/image")
    public String image(String message) throws Exception {
        String url = "https://dashscope.oss-cn-beijing.aliyuncs.com/images/dog_and_girl.jpeg";
        List<Media> mediaList = List.of(new Media(MimeTypeUtils.IMAGE_JPEG, new URI(url)));

        UserMessage userMessage = UserMessage.builder()
                .text("请分析这张图片并描述内容: "+message)
                .media(mediaList)
                .build();

        ChatResponse chatResponse = chatClient.prompt(new Prompt(userMessage))
                .call()
                .chatResponse();

        return chatResponse.getResult().getOutput().getText();
    }
}

